﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.DAL;
using SMS.DAL.Providers;

namespace SMS.Business.Users
{
    public class UsersBusiness : BusinessBase<SMS.DAL.User, SMS.DAL.Providers.UserSearchCriteria>
    {
        private UserProvider provider;
        public UsersBusiness()
        {
            provider = new UserProvider();
        }
        public User UserLogIn(string username, string password)
        {
            var user = provider.GetByUsernameAndPassword(username, password);
            return user;
        }

        public override bool Insert(User item)
        {
            try
            {
                item.Status = (int)SMS.DAL.Providers.UserStatusEnum.Available;
                provider.Insert(item);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public override bool Update(User updatedItem)
        {
            try
            {
                provider.Update(updatedItem);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public override bool Delete(int id)
        {
            try
            {
                provider.Delete(id);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public override User GetByID(int id)
        {
            return provider.GetByID(id);
        }

        public override List<User> Search(UserSearchCriteria SearchCriteria)
        {
            return provider.Search(SearchCriteria);
        }

        public List<User> GetAvaialableWorkers()
        {
            return provider.GetAvaialableWorkers();
        }

        public bool CheckUserNameAvailabilty(string UserName)
        {
            return provider.CheckUserNameAvailabilty(UserName);
        }

        public User GetStockAdmin(int StockID)
        {
            return provider.GetStockAdmin(StockID);
        }
    }
}
